package servlets;

import java.io.IOException;
import java.util.List;

import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import parser.WriterXML;

import entitiesdto.EnvioCentroDistribucionDTO;

import businessdelegate.FacadeBusinessDelegate;

 public class ReposicionArticulosSVL extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   
	public ReposicionArticulosSVL() {
		super();
	}   	
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}  	
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		HttpSession session = request.getSession(true);
		WriterXML writer = new WriterXML();
		List<EnvioCentroDistribucionDTO> envio;
		try {
			envio = FacadeBusinessDelegate.getInstance().generarReposicionArticulos();
			for(EnvioCentroDistribucionDTO envios: envio){
				writer.generarReposicionArt( envios , "1");
			}
			session.setAttribute("enviosRealizados", envio);

		} catch (NamingException e1) {
			e1.printStackTrace();
		}

		RequestDispatcher dispatcher = request.getRequestDispatcher("/reponerArticulos.jsp");

		try {
			dispatcher.forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}   	  	    
}